<!--项目搜索-->
<template>
    <div class="project-search-wrapper" ref="projectBoxRef">
        <a-table :scroll="{x:0,y:200}" :columns="columns" :data-source="tableData" :customRow="customClick" bordered :pagination="pagination" :loading="isSearch">
        </a-table>
    </div>
</template>
<script>
import { pageList } from "@/api/erp/maintenance"; //获取项目数据

const columns = [
    { title: "项目编码", dataIndex: "code" },
    { title: "项目名称", dataIndex: "name" },
    { title: "所属部门", dataIndex: "department" },
    { title: "负责人", dataIndex: "liablePersonNames" },
];
export default {
    props: {

    },
    data() {
        return {
            pagination: {
                current: 1,
                pageSize: 20,
                total: 0,
                size: 'small',
                onChange: (page, pageSize) => {
                    this.pagination.current = page;
                    this.pagination.pageSize = pageSize;
                    this.getData();
                }
            },
            columns,
            tableData: [],
            customClick: (record, index) => ({
                on: {
                    click: (event) => {
                        event.preventDefault();
                        console.log('点击的行数', record, index);
                        this.$emit('check', record)
                    },
                },
            }),
            isSearch: false,
        }
    },
    created() {
        this.getData();
    },
    methods: {
        getData(code) {
            //获取右侧表数据
            var _this = this;
            let params = {
                current: this.pagination.current,
                size: this.pagination.pageSize,
                searchKey: code
            };
            if (!this.isSearch) {
                this.isSearch = true;
                pageList(params).then((response) => {
                    if (response.code == 200) {
                        // _this.tableData = res.data.records;
                        // Object.assign(_this.pagination, {
                        //     total: res.data.total,
                        // });

                        const { records, total, current, size } = response.data;
                        let page = {
                            total: total,
                            pageSize: size,
                            current: current
                        }
                        _this.pagination = Object.assign(_this.pagination, page);
                        _this.tableData = records;

                        this.isSearch = false;
                    } else {
                        // _this.$message.warning(res.message);
                    }
                });
            }

        },
        handleEnter() {
            if (this.tableData != '' && this.tableData != null) {
                this.$emit('check', this.tableData[0])
            } else {
                this.$message.warning('请选择一条数据')
                return;
            }
        },
        changePosition(position) {
            console.log(position);
            this.$nextTick(() => {
                this.$refs.projectBoxRef.style.left = (position.left - 200) + 'px';
            })
        }
    }
}
</script>
<style lang="less">
.project-search-wrapper {
    max-height: 350px;
    position: fixed;
    z-index: 100;
    border: 1px solid #a7abb0;
    width: 500px;
    // .ant-table-wrapper .ant-table-placeholder {
    //     position: static !important;
    //     top: 0;
    // }
    .ant-table-wrapper {
        background: #eee;
    }
    .ant-table-tbody {
        cursor: pointer;
    }
}
</style>